home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / portable / newwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.8 KB  |  108 lines

  1. #define CURSES_LIBRARY    1
  2. #define    CURSES_LIBRARY    1
  3. #include <curses.h>
  4. #undef    newwin
  5.  
  6. #ifdef PDCDEBUG
  7. char *rcsid_newwin = "$Header: C:\CURSES\portable\RCS\newwin.c 2.1 1993/06/18 20:19:05 MH Rel MH $";
  8. #endif
  9.  
  10.  
  11.  
  12.  
  13. /*man-start*********************************************************************
  14.  
  15.   newwin()    - create new window
  16.  
  17.   X/Open Description:
  18.      Create a new window with the given number of lines, nlines and
  19.      columns, ncols. The upper left corner of the window is at line
  20.      begy, column begx. If either nlines or ncols is zero,
  21.      they will be defaulted to LINES - begy and COLS - begx. A
  22.      new full-screen window is created by calling newwin(0, 0, 0, 0).
  23.  
  24.   PDCurses Description:
  25.      PDCurses allows developers to provide a hook into the malloc
  26.      package used.  See initscr(3c) for more details.
  27.  
  28.      Also, when a window is created, it uses the default screen
  29.      colors and attributes in effect when initscr() was called.
  30.  
  31.   X/Open Return Value:
  32.      On success the newwin() function returns a pointer to the new
  33.      WINDOW structure created. On failure the function returns a
  34.      null pointer.
  35.  
  36.   PDCurses Errors:
  37.      The following conditions are errors:
  38.          o  number of lines   == 0,
  39.          o  number of columns == 0,
  40.          o  failure to allocate memory for the window structure
  41.  
  42.   Portability:
  43.      PDCurses    WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  44.      X/Open Dec '88    WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  45.      BSD Curses    WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  46.      SYS V Curses    WINDOW* newwin(int nlines,int ncols,int begy,int begx);
  47.  
  48. **man-end**********************************************************************/
  49.  
  50. WINDOW*    newwin(int nlines, int ncols, int begy, int begx)
  51. {
  52. extern    void*    (*mallc)( size_t );
  53. extern    void*    (*callc)( size_t, size_t );
  54. extern    void    (*fre)( void* );
  55.  
  56.     WINDOW*    win;
  57.     chtype*    ptr;
  58.     int    i;
  59.     int    j;
  60.  
  61. #ifdef PDCDEBUG
  62.     if (trace_on) PDC_debug("newwin() - called:lines=%d cols=%d begy=%d begx=%d\n",nlines,ncols,begy,begx);
  63. #endif
  64.  
  65.     if (nlines == 0)    nlines = LINES - begy;
  66.     if (ncols  == 0)    ncols  = COLS  - begx;
  67.  
  68.     if ((win = PDC_makenew(nlines, ncols, begy, begx)) == (WINDOW *) NULL)
  69.         return( (WINDOW *)NULL );
  70.  
  71.     for (i = 0; i < nlines; i++)
  72.     {
  73.         /*
  74.          * make and clear the lines
  75.          */
  76.         if ((win->_y[i] = (*callc)(ncols, sizeof(chtype))) == NULL)
  77.         {
  78.             for (j = 0; j < i; j++)
  79.             {
  80.                 /*
  81.                  * if error, free all the data
  82.                  */
  83.                 (*fre)(win->_y[j]);
  84.             }
  85.             (*fre)(win->_firstch);
  86.             (*fre)(win->_lastch);
  87.             (*fre)(win->_y);
  88.             (*fre)(win);
  89.             return( (WINDOW *)NULL );
  90.         }
  91.         else
  92.         {
  93.             for (ptr = win->_y[i];
  94.                  ptr < win->_y[i] + ncols;)
  95.             {
  96.                 /*
  97.                  * Retain the original screen attributes...
  98.                  */
  99.                 *ptr++ = _cursvar.blank;
  100.             }
  101.         }
  102.     }
  103. #ifdef UNIX
  104.     PDC_gotoxy(begy, begx);
  105. #endif
  106.     return( win );
  107. }
  108.